package cn.imvc.app.controllers.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.entities.Department;
import cn.imvc.app.entities.Menu;
import cn.imvc.app.models.MenuModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;

public class MenuControllerImpl implements MenuController {
	public Page<Department> page;
	public ViewRequest viewRequest;
	public String menuTree;
	public Menu menu;
	public int id;
	@Autowired
	private MenuModel menuModel;
	
	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String search() {
		return null;
	}

	public String index() {
		menuTree=menuModel.getMenuTree();
		return "menu/index";
	}

	public String show() {
		menu=menuModel.get(id);
		return "menu/show";
	}

	public String editNew() {
		menu=menuModel.get(id);
		return "menu/editNew";
	}

	public String create() {
		menuModel.save(id,menu);
		return Render.json(new DialogBean("200", "创建成功","menu","closeCurrent"));
	}

	public String edit() {
		menu=menuModel.get(id);
		return "menu/edit";
	}

	public String update() {
		menuModel.update(id,menu);
		return Render.json(new DialogBean("200", "修改成功","menu"));
	}

	public String destroy() {
		return Render.json(menuModel.delete(id));
	}

	public String destroyBatch() {
		return null;
	}

}
